# Contributor: z3bra <willy at mailoo dot org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=thttpd
pkgver=2.29
pkgrel=4
pkgdesc="Simple, small, portable, fast, and secure HTTP server"
url="http://www.acme.com/software/thttpd"
arch="all"
license="custom:BSD"
# No test/check available
options="!check"
install="$pkgname.pre-install"
subpackages="$pkgname-doc $pkgname-openrc"
source="http://www.acme.com/software/$pkgname/$pkgname-$pkgver.tar.gz
	thttpd.initd
	thttpd.confd
	thttpd.conf
	thttpd.logrotated
	thttpd-webgroup.patch
	forwarded-for.patch
	remove_transfer_encoding.patch
	thttpd-makeweb-notsuid.patch
	install-user.patch
	"

prepare() {
	default_prepare
	echo 'mkv       video/x-matroska' >> mime_types.txt
}

build() {
	CFLAGS="$CFLAGS -fpermissive" ./configure \
		--prefix=/usr \
		--mandir=/usr/share/man
	sed -e 's/^CFLAGS =/CFLAGS +=/' \
	    -e '/^STATICFLAG =/c STATICFLAG =' \
	    -i Makefile */Makefile
	make
}

package() {
	mkdir -p $pkgdir/usr/share/man/man1

	make \
		BINDIR="$pkgdir"/usr/sbin \
		WEBDIR="$pkgdir"/var/www/http \
		MANDIR="$pkgdir"/usr/share/man \
		WEBGROUP=www-data install

	rm -rf "$pkgdir"/var/www/http/*

	install -m755 -D "$srcdir"/$pkgname.initd \
		"$pkgdir"/etc/init.d/$pkgname
	install -m644 -D "$srcdir"/$pkgname.confd \
		"$pkgdir"/etc/conf.d/$pkgname
	install -m644 -D "$srcdir"/$pkgname.conf \
		"$pkgdir"/etc/thttpd.conf
	install -m644 -D "$srcdir"/$pkgname.logrotated \
		"$pkgdir"/etc/logrotate.d/thttpd

	install -d "$pkgdir"/var/log/thttpd
	install -d "$pkgdir"/usr/share/licenses/"$pkgname"
	head -n 26 thttpd.c > \
		"$pkgdir"/usr/share/licenses/"$pkgname"/LICENSE
	mkdir -p "$pkgdir/usr/share/doc/$pkgname"
	cat > $pkgdir/usr/share/doc/$pkgname/README.alpine <<EOF
	To use makeweb, please set suid to makeweb binary with:
	-------------------------------------------------------
	chmod 2755 /usr/sbin/makeweb
EOF
}

sha512sums="
e02ed5b889eb3c875d56503093777c542316165a8df2d83e539337fb0759b6d9728fd484123dd903af57b06c97fe339055b816cca64778b7369b94020bd61ab6  thttpd-2.29.tar.gz
bc7416986e135ade401721708060b94ce3bb885a3aa40893d68abc1b305c13609e086fbb48f8db11656902c294bf558a81814013ef3a14d73f0c5f0df0decb7d  thttpd.initd
9b4309c2bc88d11ce71d40ab813e9cbe78e4ec7368e3e98f35da1d5a324ee0630a6892b43f58f84490e2b534a573673b106a9d5dd406fedefb2a4c664e455aa1  thttpd.confd
f1b86a554177a5f2a343abb4aac6fa9bc06dafd7cabdaf8329e6478bcc296f39a56d839e85ac4bf77b682e6e9cdbbe844732dfac034d0d775b65cdeaefc4349e  thttpd.conf
5b2800825583e93cf4be76e71d2840b9894c1779a810d562a0b6145cae0c7504dadfdc1e844f1611a48cca3b4518d41b47e41a68f33043d58ffde85f1e56e3f3  thttpd.logrotated
349721da9e670ca666891f98ca338ae0041c09b353fc42bdd87015803f0b668478be8e48f36d5b56b5e172d3a7b262bf4a71c9619607a068e41c2bc292bde2be  thttpd-webgroup.patch
02c079ca104f2358cd20756082657dca96f7a88cbeb611de81504f1581c5e085a7a2765ec55b6e0ae1948803afced85e8a45fc6deb2fef1ec5ba1ba96ce68b4b  forwarded-for.patch
6536ae6c25dbf79aec43e3d0596ad135ab3ab6e7cd3a5e3c895a289114c08c03c20357ffb4542decfc4d508039a5045db71fb36002c8ba94dbd6356cad32bae4  remove_transfer_encoding.patch
1138a827049f73b43ce142c914fad0670bcd4577de16485ade024314c616056ab6789897663d8b6592331354d44065eae7aa712e20f5c930a80513448416fa17  thttpd-makeweb-notsuid.patch
9b674b108961289d8869c31978a4c1822de54377d7a35907ae29d47ab2f5003d760f2970dec3bc11780f116d8f3c532f6726b76e0ebf1d0a89c85ce3eb0963ba  install-user.patch
"
